package com.poh.service.impl;

import com.poh.mapper.TopicMapper;
import com.poh.pojo.Reply;
import com.poh.pojo.Topic;
import com.poh.service.TopicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
@Service
public class TopicServiceImpl implements TopicService {
    @Autowired
    TopicMapper topicMapper;
    @Override
    public List<Topic> getTopicByCourseId(int courseId) {
        return topicMapper.getTopicByCourseId(courseId);
    }

    @Override
    public int addTopic(Topic topic) {
        LocalDate localDate = LocalDate.now();
        LocalTime localTime = LocalTime.now();
        topic.setTopicTime(localDate.format(DateTimeFormatter.ISO_DATE) + " " + localTime);
        return topicMapper.addTopic(topic);
    }

    @Override
    public Topic getTopicById(int topicId) {
        return topicMapper.getTopicById(topicId);
    }

    @Override
    public List<Topic> getTopicByUserId(int userId) {
        return topicMapper.getTopicByUserId(userId);
    }


    @Override
    public int deleteTopic(int topicId) {
        return topicMapper.deleteTopic(topicId);
    }
}
